package com.enbatis.mybatisplugs.controller;

import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.enbatis.mybatisplugs.entity.SysUserRelDept;
import com.enbatis.mybatisplugs.service.SysUserRelDeptService;


import java.util.List;

@RestController
@RequestMapping("v1/sys_user_rel_dept")
public class SysUserRelDeptController extends BaseController {

@Autowired
private SysUserRelDeptService sysUserRelDeptService;


    @PostMapping("/add")
    public ResultReturn<SysUserRelDept> add(@RequestBody SysUserRelDept sysUserRelDept){
        return  success(sysUserRelDeptService.insert(sysUserRelDept));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(sysUserRelDeptService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,@RequestBody SysUserRelDept sysUserRelDept){
        sysUserRelDept.setId(id);
        return success(sysUserRelDeptService.updateById(sysUserRelDept));
    }


    @GetMapping("/{id}")
    public ResultReturn<SysUserRelDept> get(@PathVariable("id") Long id) {
        return success(sysUserRelDeptService.getById(id));
    }


    @GetMapping("/list")
    public ResultReturn<List<SysUserRelDept>> getList(SysUserRelDept sysUserRelDept){
        return success(sysUserRelDeptService.list(new Wrapper<>(sysUserRelDept)));
    }

}
